<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    #result {
      width: 200px;
      height: 100px;
      border: 1px solid red;
    }
  </style>
</head>
<body>
  <button id="btn">点击发送请求</button>
  <div id="result"></div>
  <script>
    const div = document.getElementById('result')
    const btn = document.getElementById('btn')
    btn.addEventListener('click', function() {
      // 创建对象
      const xhr = new XMLHttpRequest()
      // 初始化 请求方法和请求url
      // 获取当前时间戳 不走本地缓存 请求新的数据
      xhr.open('GET', 'http://127.0.0.1:8000/ie-server?t='+Date.now())
      // 发送请求
      xhr.send()
      // 事件绑定
      xhr.onreadystatechange = function () {
        if (xhr.readyState === 4) {
          if (xhr.status >= 200 && xhr.status < 300) {
            // 状态码
            console.log(xhr.status)
            // 状态字符串
            console.log(xhr.statusText)
            /// 响应头
            console.log(xhr.getAllResponseHeaders()
            )
            // 响应体
            console.log(xhr.response)
            div.innerHTML = xhr.response
          }
        }
      }
    })
  </script>
</body>
</html>